#pragma once;

#include "physics_object.h"
#include "common.h"
#include "collision_primitive.h"
#include "collisiondetector.h"

class Shader;

namespace TorPhysix
{
	class Box;

class Ball : public TorPhysix::PhysicsObject
{
public:
	Ball();

	virtual ~Ball()
	{
		//std::cout << "ball dtor" << std::endl;
		delete collisionSphere;
	}

	void vRender();
	void vRenderDebug();
	void vPicking();
	void vRenderShadow();

	virtual void vSetState(real x, real y, real z, Quatf orientation, Vec3f collisionSize, real mass, Vec3f acceleration)
	{
		setIdentity( collisionPrimitive->offset ); //  no offset from rigid body origin
		collisionPrimitive->body->setPosition( Vec3f( x, y, z ) );
		collisionPrimitive->body->setOrientation( Quatf(1,0,0,0) );
		collisionPrimitive->body->setVelocity( Vec3f(0.0f, 0.0f, 0.0f) );
		collisionPrimitive->body->setRotation( Vec3f(0.0f, 0.0f, 0.0f) );
		collisionPrimitive->body->setAcceleration( acceleration );

		Mat3f sphereTensor;
		setIdentity(sphereTensor);
		sphereTensor *= 1.0f;
		collisionPrimitive->body->setInertiaTensor(sphereTensor);
		collisionSphere->radius = collisionSize.x();
		collisionPrimitive->body->setDamping(0.96f, 0.9f);
		collisionPrimitive->body->setMass(mass);
		collisionPrimitive->body->clearAccumulators();
		collisionPrimitive->body->calculateDerivedData();
		collisionPrimitive->calculateInternals();
	}

	
	virtual void vScale( Vec3f scaleAxis, float scaleMagnitude );
	bool vIsManipulator() const { return false; }
	virtual void vInteractWith( SceneObject *mutator ){}
	virtual bool isSphere() { return true; }

	virtual void acceptVisitor( PhysicsObject& visitor, CollisionData* cData )
	{ 
		visitor.collideAgainst( *this, cData ); 
	}

	virtual void collideAgainst( TorPhysix::Box& box, CollisionData* cData );

	virtual void collideAgainst( Ball& ball, CollisionData* cData );

	TorPhysix::CollisionSphere *collisionSphere;

private:

	Shader *normalShader;
	
};

}